package yogiro.service;

import java.sql.SQLException;
import java.util.ArrayList;

import yogiro.dao.NoticeCommentDAO;
import yogiro.to.NoticeCommentTO;
import yogiro.util.Utilities;

public class NoticeCommentService{
	private NoticeCommentDAO commentDAO;
	
	
	public void setCommentDAO(NoticeCommentDAO commentDAO){
		this.commentDAO = commentDAO;
	}
	
	
	
	public String replace(String content){
		content = content.replace("<", "&lt");
		content = content.replace(">", "&gt");
		content = content.replace(" ", "&nbsp");
		content = content.replace("\n", "<br>");
		return content;
	}
	
	
	public NoticeCommentTO insertComment(String content, String id,int noticeNo)throws SQLException{
		String writedate = Utilities.getNow();
		int commentNo = commentDAO.sequence();
		NoticeCommentTO cto = new NoticeCommentTO(commentNo, content, writedate, "1", noticeNo);
		commentDAO.insertComment(cto);
		return cto;
	}
	public ArrayList<NoticeCommentTO> selectAllComment(int noticeNo)throws SQLException{
		System.out.println(noticeNo);
		System.out.println("안오남?");
		System.out.println("머하냐고"+(ArrayList<NoticeCommentTO>)commentDAO.selectAllComment(noticeNo));
		return (ArrayList<NoticeCommentTO>)commentDAO.selectAllComment(noticeNo);
	}

	
	
	public void updateCommentReply(int refamily,int restep) throws SQLException{
		commentDAO.updateCommentReply(refamily, restep);
	}
	
}
